/**
 * ReportGear(2011)
 */
package net.abbp.report.view.cell.value;

/**
 * 公式对象
 * 
 * @version 1.0 2011-4-4
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 */
public class FormulaValue extends AbstractCellObject {
    /**
     * 公式值
     */
    private String formula = "";

    /**
     * 构造器
     */
    public FormulaValue() {
        this("");
    }

    /**
     * 构造器
     * 
     * @param formula
     *            公式
     */
    public FormulaValue(String formula) {
        this.formula = formula;
    }

    /**
     * 获取公式值
     * 
     * @return 工时值
     */
    public String getFormula() {
        if (formula.startsWith("=")) {
            return formula.substring(1);
        } else {
            return formula;
        }
    }

    public void setFormula(String formula) {
        if (formula.startsWith("=")) {
            this.formula = formula.substring(1);
        } else {
            this.formula = formula;
        }
    }

    @Override
    public String toString() {
        if (this.formula == null) {
            return "";
        }

        if (this.formula.startsWith("=")) {
            return this.formula;
        } else {
            return "=" + this.formula;
        }
    }

    @Override
    public FormulaValue clone() {
        return (FormulaValue) super.clone();
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((formula == null) ? 0 : formula.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        FormulaValue other = (FormulaValue) obj;
        if (formula == null) {
            if (other.formula != null)
                return false;
        } else if (!formula.equals(other.formula))
            return false;
        return true;
    }
}
